class Trie:
    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.tree = {}

    def insert(self, word: str) -> None:
        """
        Inserts a word into the trie.
        """
        tree = self.tree
        for c in word:
            if c in tree:
                tree = tree[c]
            else:
                tmp = {}
                tree[c] = tmp
                tree = tmp
        tree["X"] = True

    def search(self, word: str) -> bool:
        """
        Returns if the word is in the trie.
        """
        tree = self.tree

        for c in word:
            if c in tree:
                tree = tree[c]
            else:
                return False

        return "X" in tree

    def startsWith(self, prefix: str) -> bool:
        """
        Returns if there is any word in the trie that starts with the given prefix.
        """
        tree = self.tree
        for c in prefix:
            if c in tree:
                tree = tree[c]
            else:
                return False

        return True


if __name__ == "__main__":
    trie = Trie()
    trie.insert("apple")
    trie.insert("app")
    print(trie.tree)
    print(trie.search("applex"))